package online.hxstart.code.concurrent.chapter10;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @author huxing
 * @date 2019/7/11 星期四 20:26
 * @describe
 */
public class MyClassLoaderTest {

  public static void main(String[] args)
      throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
    //

    ClassLoader extClassLoader = MyClassLoader.class.getClassLoader().getParent();

    MyClassLoader myClassLoader = new MyClassLoader(extClassLoader,
        "D:/work/");

    Class<?> aClass = myClassLoader
        .loadClass("HelloWorld111");

    System.out.println(aClass);
    System.out.println(aClass.getClassLoader());
    Object helloWorld = aClass.newInstance();
    System.out.println(helloWorld);
    Method welcomeMethod = aClass.getMethod("welcome");
    String result = (String) welcomeMethod.invoke(helloWorld);
    System.out.println("Result：" + result);

    IHelloWorld iHelloWorld = (IHelloWorld) aClass.newInstance();

    System.out.println("IHelloWorld" + iHelloWorld.welcome());
    System.out.println("IHelloWorld" + iHelloWorld.sum(5, 8));
  }
}
